package com.google.code.timetrail.gui;

import java.awt.CardLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractButton;
import javax.swing.AbstractListModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import com.google.code.timetrail.backend.*;

public class RationsPaceFrame extends JPanel{
    /**
     * 
     */
    private static final long serialVersionUID = -7826090580628698909L;
    private JLabel paceLabel;
    private JLabel rationsLabel;
    private JList rationsList;
    protected ConsumptionRate rations;
    private JList paceList;
    private JButton nextButton2;
    protected Component frame;
    private AbstractButton backButton;
    private Control myGameControl;
    private RationsPaceFrameBackend rationsPaceBackend;
    private JPanel myCD;

    public RationsPaceFrame(Control gameControl, JPanel cd){
        this.myGameControl = gameControl;
        this.myCD = cd;
        rationsPaceBackend = new RationsPaceFrameBackend(this.myGameControl);
        //contentPane.add(paceAndRationsPanel, "name_1317840867491837000");
        setLayout(null);
        
        paceLabel = new JLabel(rationsPaceBackend.getPaceLabelText());
        paceLabel.setBounds(164, 131, 73, 16);
        add(paceLabel);
        
        rationsLabel = new JLabel(rationsPaceBackend.getRationsLabelText());
        rationsLabel.setBounds(139, 285, 98, 16);
        add(rationsLabel);
        
        rationsList = new JList();
        rationsList.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                rationsPaceBackend.rationsListChanged(rationsList.getSelectedIndex());
                
            }
        });
        rationsList.setModel(new AbstractListModel() {
            /**
             * 
             */
            private static final long serialVersionUID = -4548133300722898773L;
            String[] values = rationsPaceBackend.getRationsValues();
            public int getSize() {
                return values.length;
            }
            public Object getElementAt(int index) {
                return values[index];
            }
        });
        rationsList.setBounds(250, 285, 118, 85);
        add(rationsList);
        
        paceList = new JList();
        paceList.addListSelectionListener(new ListSelectionListener() {
            

            public void valueChanged(ListSelectionEvent arg0) {
                rationsPaceBackend.paceValueChanged(paceList.getSelectedIndex());

            }
        });
        paceList.setModel(new AbstractListModel() {
            /**
             * 
             */
            private static final long serialVersionUID = 6536129015703048805L;
            String[] values = rationsPaceBackend.getPaceValues();//
            public int getSize() {
                return values.length;
            }
            public Object getElementAt(int index) {
                return values[index];
            }
        });
        paceList.setBounds(250, 131, 118, 68);
        add(paceList);
        
        nextButton2 = new JButton(rationsPaceBackend.getNextButtonText());
        nextButton2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                rationsPaceBackend.pressNextButton();
                myCD.add(new StoreFrame(myGameControl, myCD), "name_1317840867491837001");
                CardLayout cd = (CardLayout) myCD.getLayout();
                cd.next(myCD);
            }
        });
        
        nextButton2.setBounds(447, 412, 117, 29);
        add(nextButton2);
        
        backButton = new JButton(rationsPaceBackend.getBackButtonText());
        backButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                rationsPaceBackend.pressBackButton();
                CardLayout cd = (CardLayout) myCD.getLayout();
                cd.previous(myCD);
            }
        });
        backButton.setBounds(320, 412, 117, 29);
        add(backButton);
    }
}
